#ifndef QTIMEWATCH_H_A1607E53_EBD8_4F07_A7C9_83A1613AA139
#define QTIMEWATCH_H_A1607E53_EBD8_4F07_A7C9_83A1613AA139

#include "AudioUtils_global.h"

#include <QTime>
#include <QDebug>

namespace AudioUtils {

class AUDIOUTILS_EXPORT QTimeWatch
{
public:
	QTimeWatch(const QString& name = "")
		: name(name)
	{
		start();
	}

	QTimeWatch(const QString& name, bool start)
		: name(name)
		, watching(start)
	{
		if (watching)
		{
			time.start();
		}
	}

	~QTimeWatch()
	{
		stop();
	}

public:
	void watch(const QString& name)
	{
		this->name = name;
	}

	void start() 
	{ 
		if (watching)
		{
			time.restart();
		}
		else
		{
			time.start();
		}
	}

	void stop() 
	{ 
		if (watching)
		{
			qDebug() << name << time.elapsed() / 1000.0 << "s";
			watching = false;
		}
	}

private:
	QString name;
	QTime time;
	bool watching;
};

}

#endif // QTIMEWATCH_H_A1607E53_EBD8_4F07_A7C9_83A1613AA139
